<template>
  <div class="home-icons">
    <swiper ref="mySwiper" :options="swiperOptions">
      <swiper-slide v-for="(item,index) in page" :key="index">
        <div class="icon-item" v-for="page in item" :key="page.id">
          <img :src="page.imgUrl" alt="">
          <p>{{ page.title }}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeIcons",
  props: {
    iconsList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      swiperOptions: {
        pagination: {
          el: '.swiper-pagination'
        }
      }
    }
  },
  computed: {
    page() {
      let pages = []
      this.iconsList.forEach((item,index) => {
        let idx = Math.floor(index / 8)
        if(!pages[idx]) pages[idx] = []
        pages[idx].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped>
  .home-icons {
    width: 100%;
    overflow: hidden;
    background-color: #fff;
    height: 0;
    padding-bottom: 50%;
    margin-bottom: .2rem;
  }
  .icon-item {
    width: 25%;
    /* 防止下面文字图片加载慢的时候突然掉下来 */
    height: 0;
    padding-top: .1rem;
    padding-bottom: calc(25% - .1rem);
    float: left;
  }
  .icon-item img {
    width: 1.1rem;
    height: 1.1rem;
    display: block;
    margin: 0 auto;
  }
  .icon-item p {
    font-size: .28rem;
    text-align: center;
    margin-top: .1rem;
    color: var(--color-icon);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  /* stylus中的穿透覆盖样式 */
  .home-icons >>> .swiper-pagination-bullet-active {
    background: var(--color-background);
  }
</style>
